package com.dayday.edu.service.impl;

import com.dayday.edu.annotation.Autowired;
import com.dayday.edu.annotation.Service;
import com.dayday.edu.annotation.Transactional;
import com.dayday.edu.dao.AccountDao;
import com.dayday.edu.pojo.Account;
import com.dayday.edu.service.TransferService;
import com.dayday.edu.utils.ConnectionUtils;
import com.dayday.edu.utils.TransactionManager;

/**
 * @author dayday
 */
@Service(value = "TransferService")
public class TransferServiceImpl implements TransferService {

    @Autowired
    private AccountDao accountDao;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    @Override
    @Transactional
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);
            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);
            accountDao.updateAccountByCardNo(to);
            accountDao.updateAccountByCardNo(from);

    }
}
